// pages/leiList/leiList.js
var app = getApp();
var httptool = require("../../utils/zry.httptool.js");
let tabjs = require("../../utils/tab.js");
Page({
  data:{
     tabNum: 1,  //tab编号
     rankings:[],//排名列表
     selfScore:{},//自己的成绩
     activeIndex:'2',
     msgprop:'',//消息提示  
     noData: false,
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
    let that=this;
    that.getTopList();
   
  },
  daLei:function(e){
    httptool.login(function () {
      tabjs.daleiBtnClick();
    }); 
  },
  myCenter:function(e){
    wx.redirectTo({
      url: '/pages/myCenter/myCenter',
    })
  },
  leiCircle:function(e){
    wx.navigateTo({
      url: '/pages/index/index',
    })
  },
  //全国排名，本地排名，年龄排名导航切换事件
  tabClick:function(e){
      let that=this;
      let num=e.currentTarget.dataset.num;
      that.setData({
        tabNum:num,
        rankings:[],
        noData: false
      });
      that.getTopList();
  },
  Posted: function () {//发帖
    let that = this;
    let CircleId = that.data.tabNum;
    wx.navigateTo({
      url: '/pages/share/share?CircleId=' + CircleId,
    });
  },
  searchBtn: function () {//搜索
    wx.navigateTo({
      url: '/pages/search/search?stype='+1,
    });
  },
  enterIndex:function(e){//擂手圈跳转
    wx.redirectTo({
      url: '/pages/index/index',
   });
  },
  friendDetail:function(e){//点击头像进入某人的详情页，查看对方信息，帖子
    let that=this;
    let ToUserId=e.currentTarget.dataset.userid;
    wx.navigateTo({
      url: '../followdetail/followdetail?ToUserId='+ToUserId,
    });
  },
  getTopList:function(e){
      let that=this;
      let param={};
      param.userId=app.getStorage('customerId');
      param.userType=that.data.tabNum;
      httptool.ajaxPost("api/Customer/GetTopList", param, function (res) {
        if (res.suc) {
          let data = app.notNull(res.data, []);
          if (data.length > 0) {
            for(let i=0;i<data.length;i++){
                data[i].listName=that.data.listname;
                if(param.userType==1 || param.userType==2){
                  data[i].listName='武力指数';
                }else{
                  data[i].listName='战斗力';
                }
            }
            that.setData({selfScore:data[0]});
            data.splice(0,1);//删除数组的一个元素
            that.setData({ rankings: data, noData: data.length == 0});
          }else{
            that.setData({ noData: true });
          }
        } else {
          app.showNotify(that, res.msg);
        }
      });
  },
  onReady:function(){
    // 页面渲染完成
  },

})